<?php
/*
 * @Author: your name
 * @Date: 2020-11-10 13:44:09
 * @LastEditTime: 2020-12-17 11:21:29
 * @LastEditors: Please set LastEditors
 * @Description: 资产位置数据验证器
 * @FilePath: /special/application/adminapiv3/validate/AddressValidate.php
 */

namespace app\adminapiv3\validate;


use think\Validate;

class AddressValidate extends Validate
{
    //验证规则
    protected $rule = [
        //资产位置ID
        'id|资产位置ID' => 'require|integer|length:1,10',
        //资产位置名
        'name|资产位置名称' => 'require|max:50|unique:host_address',
        //资产位置
        'address|资产位置' => 'require|max:255',
        //网络运营商
        'provider|服务提供商' => 'require|in:1,2,3',
        //资产位置类型
        'type|资产位置类型' => 'require|in:1,2',
    ];

    //错误信息
    protected $message = [
        'name.unique' => '位置名称已存在',
        'provider.in' => '服务提供商格式错误',
        'type.in' => '资产位置类型格式错误',
    ];

    //验证场景
    protected $scene = [
        //添加
        'add' => ['name','address','provider','type'],

        //删除
        'del' => ['id'],
    ];

    public function sceneModify()
    {
        return $this->only(['id','name','address','provider','type'])
            ->remove('name', 'unique');
    }
}